package freespiritsocial.io.user.viewmodel

import freespiritsocial.io.user.network.apiService
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.callback.databind.BooleanObservableField
import me.hgj.jetpackmvvm.callback.databind.StringObservableField
import me.hgj.jetpackmvvm.ext.request
import me.hgj.jetpackmvvm.ext.requestNoCheck
import me.hgj.jetpackmvvm.network.AppException
import me.hgj.jetpackmvvm.util.MD5Utils

class ResetPasswordViewModel: BaseViewModel() {
    val mobile = StringObservableField()
    val areaCode = StringObservableField("+44")
    val code = StringObservableField()
    val confirmPassword = StringObservableField()
    val newPassword = StringObservableField()
    val isForget = BooleanObservableField(false)

    fun resetPassword(action: () -> Unit) {
        if (confirmPassword.get() != newPassword.get()) {
            toast.postValue("The passwords entered two times are inconsistent")
            return
        }
        request({
            apiService.updatePassword(MD5Utils.md5(newPassword.get()))
        },{
            action()
        })
    }


}
